@extends('manage.layout')
@section('link')
    <style>
        ul,li,ol{
            list-style-type: none;
        }
        .setul li{
            float: left;
            margin:0 30px 0 0;
        }
    </style>
@stop
@section('content')
    <section class="content-header">
        <h1>
           产品列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Product</a></li>
            <li class="active">Product</li>
        </ol>
        {{--<div class="input-group margin">--}}
            {{--<form action="/product" method="get">--}}
                {{--<select style="width: 150px" id="sel"  name="type" class="form-control" onchange="select()">--}}
                    {{--@foreach($navigation as $value)--}}
                        {{--<option value="{{ $value['id'] }}">{{ $value['navigation'] }}</option>--}}
                    {{--@endforeach--}}
                {{--</select>--}}

                {{--<div style="float: left" id="form">--}}
                    {{--<input id="datepicker" style="width: 200px"  name="param" type="text" class="form-control">--}}
                {{--</div>--}}
                {{--<input  type="submit" class="btn btn-info btn-flat" value="Go!">--}}
            {{--</form>--}}
        {{--</div>--}}
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box box-primary">
                    <div class="box-body">
                        <div class="input-group">
                            <form action="/product" method="get">
                                <ul class="setul">
                                    <li>
                                        <select style="width: 150px" name="type" class="form-control" >
                                            @foreach($navigation as $value)
                                                <option value="{{ $value['id'] }}">{{ $value['navigation'] }}</option>
                                            @endforeach
                                        </select>
                                    </li>
                                    <li>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control" name="start_time" id="start_time" placeholder="开始时间">
                                        </div>
                                    </li>
                                    <li>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control" name="end_time" id="end_time" placeholder="结束时间">
                                        </div>
                                    </li>
                                    <li>
                                        <input style="width: 200px;"  name="param" type="text" class="form-control" value="" placeholder="关键字">
                                        <input  type="submit" class="btn btn-info btn-flat" value="Go!">
                                    </li>
                                </ul>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="example2" class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                @foreach($navigation as $nav)
                                    <th>
                                        {{$nav['navigation']}}&nbsp;&nbsp;
                                        @if($nav['navigation'] == '更新时间')
                                            <a href="/product?type={{$search}}&param={{$param}}&orderBy=1"><i class="fa fa-arrow-up"></i></a>&nbsp;&nbsp;
                                            <a href="/product?type={{$search}}&param={{$param}}&orderBy=2"><i class="fa fa-arrow-down"></i></a>
                                        @endif
                                    </th>
                                @endforeach
                                <th>状态</th>
                                <th>产品图片</th>
                                <th>产品附件</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($product as $k=>$p)
                                <tr>
                                    <td>{{ $p['id'] }}</td>
                                    {{--<td>{{ $p['create_time'] }}</td>--}}
                                    <td>{{date('Y-m-d',strtotime($p['update_time']))}}</td>
                                    <td>{{ $p['rank'] }}</td>
                                    <td><a href="/product?type=4&param={{$category[$k]['one']}}">{{$category[$k]['one']}}</a></td>
                                    <td><a href="/product?type=5&param={{$category[$k]['two']}}">{{$category[$k]['two']}}</a></td>
                                    <td>{{ $p['name'] }}</td>
                                    <td>{{ $p['price'] }}元</td>
                                    <td>{{ $p['period'] }}天</td>
                                    <td>{{ $p['firm'] }}</td>
                                    <td>{{ $p['performance'] }}</td>
                                    <td>
                                        <a href="/product?type=100&param={{$p['status']}}">
                                            @if($p['status'] == 0)禁用中
                                            @else已启用
                                            @endif
                                        </a>
                                    </td>
                                    <td><a href="/product/picture/{{ $p['id'] }}" class="btn btn-primary btn-xs" >管理图片</a></td>
                                    <td><a href="/product/annex/{{ $p['id'] }}" class="btn btn-primary btn-xs" >管理附件</a></td>
                                    <td>
                                        <a class="btn btn-primary btn-xs"  href="{{ url('product/getProduct/'.$p['id']) }}">修改<a>
                                        @if($p['status'] == 1)
                                            <a id="setStatus" class="btn btn-warning btn-xs" href="javascript:setStatus('{{ $p['id'] }}',0)">禁用<a>
                                        @elseif($p['status'] == 0)
                                            <a id="setStatus" class="btn btn-success btn-xs" href="javascript:setStatus('{{ $p['id'] }}',1)">启用<a>
                                        @endif
                                        {{--<a class="btn btn-danger btn-xs" href="javascript:delProduct({{ $p['id'] }})">删除<a>--}}
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div style="text-align: center;">
                        {!! $product->appends(['type'=>$search,'param'=>$param,'orderBy'=>$orderBy,'start_time'=>$start_time,'end_time'=>$end_time,'count'=>$count])->links() !!}
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
	<script>
        $(function () {
            //Date picker
            $('#start_time').datepicker({
                format: "yyyy-mm-dd",
                language: "zh-CN",
                autoclose: true
            });
            $('#end_time').datepicker({
                format: "yyyy-mm-dd",
                language: "zh-CN",
                autoclose: true
            });
        });
		function delProduct(id) {
            layer.confirm('删除后不可恢复，是否继续?', {
                btn:['确定','取消']
            },function() {
                $.ajax({
                    url: '/product/productDelete',
                    type: "GET",
                    data: {id:id},
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
                            window.location.href = "product";
                            layer.msg(res.msg)
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        }
        //禁用,启用
        function setStatus(id,status) {
            $.ajax({
                url: '/product/setStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href = '/product';
                        layer.msg(res.msg, {time:1500, icon:6});
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
        }
	</script>
@stop
